<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script>
    var itemClass = "";
    orderTextId = "#orderText";
    $(function(){
        itemClass = $("#itemClass").val();
        if(itemClass == 0){
            autoCompleteDrug("orderText");
        } else if(itemClass == 1){
            autoCompleteClinic("orderText");
        }
    })

    /*诊疗项目补全*/
    function autoCompleteClinic(inputId) {
        $("#"+inputId).flushCache();
        $("#clinicItemId").val("");
        $("#orderClass").val("");
        $("#performedBy").val("");
        var url = "${ctx}/oper/clinicItemDict/automatic?itemClass=E,K,Z";
        autoComplete(inputId, url,
                function (data) {
                    var rows = [];
                    for (var i = 0; i < data.length; i++) {
                        rows[rows.length] = {
                            data: data[i],
                            value: data[i].id,
                            result: data[i].itemName
                        };
                    }
                    return rows;
                }, function (data, i, max) {
                    return "类别："+data.expand1+"|名称：" + data.itemName + "|价格：" + data.price+"元"+"|执行科室"+data.expand2;
                }, function (event, data, formatted) {
                    $("#clinicItemId").val(data.id);
                    $("#orderClass").val(data.itemClass);
                    $("#performedBy").val(data.performedBy);
                    $("#price").val(data.price);
                    $("#singleDose").val(1);
                })
    }
    /*药品自动补全*/
    function autoCompleteDrug(inputId) {
        $("#"+inputId).flushCache();            //刷新缓存（非常重要）
        $("#clinicItemId").val("");
        $("#orderClass").val("");
        $('#singleDoseUnit').val("");//最小单位
        $('#packageSpec').val("");//包装规格
        $('#firmId').val("");
        $('#firmName').val("");
        var url = "${ctx}/orders/orders/autoComplete";
        autoComplete(inputId, url,
                function (data) {
                    var rows = [];
                    for (var i = 0; i < data.length; i++) {
                        rows[rows.length] = {
                            data: data[i],
                            value: data[i].price_id,
                            result: data[i].drug_name
                        };
                    }
                    return rows;
                }, function (data, i, max) {
                    console.info(data);
                    return data.drug_name + "|" + data.package_spec + "|" +data.packageunit + "|" + data.min_spec + "|" + data.minunits + "|" + data.price + "元 |" + data.firm_name + "|库存量：" + data.quantity;
                }, function (event, data, formatted) {
                    console.log(data);
                    $("#clinicItemId").val(data.price_id);
                    $("#orderClass").val(data.durg_class);
                    $('#singleDoseUnit').val(data.dose_units);//最小单位
                    $('#minUnits').val(data.minunits);//最小单位翻译
                    $('#doseUnitsMetering').val(data.dose_per_unit);//最小单位计量
                    $('#drugUnits').val(data.packageunit);//包装单位
                    $('#packageSpec').val(data.package_spec);//包装规格
                    $('#minSpec').val(data.min_spec); // 最小规格
                    $('#firmId').val(data.firm_id);
                    $('#firmName').val(data.firm_name);
                    $('#price').val(data.price);
                })
    }



    $(function(){
        $("#btnCancel").on('click',function(){
            showDiv();
        })

        if (itemClass == "0") {
            $(orderTextId).attr("id", "drugText");
            orderTextId = "#drugText";
            autoCompleteDrug("drugText");
            //选择的是药品，可以选择单位剂量+必填的
            $("#singleDose").removeAttr("disabled");
            $("#singleDose").attr("data-parsley-required", "true");
            $("#repeatIncaditor").removeAttr("disabled");
            $("#repeatIncaditor").attr("data-parsley-required", "true");
            $("#administration").removeAttr("disabled");
            $("#administration").attr("data-parsley-required", "true");
            $("#billingAttr").removeAttr("disabled");
            $("#billingAttr").attr("data-parsley-required", "true");
            $("#nursePerformTime").removeAttr("disabled");
            $("#nursePerformTime").attr("data-parsley-required", "true");

//               $("#performFreq").removeAttr("disabled");
//               $("#performFreq").attr("data-parsley-required","true");
        } else if (itemClass == "1") {
            $("#billingAttr option[value='2']").remove(); //删除Select中Text='4'的Option
            $(orderTextId).attr("id", "clinicText");
            orderTextId = "#clinicText";
            autoCompleteClinic("clinicText");
            //选择的是非药品，不能选择单位剂量+非必填项
            $("#singleDose").val("");
            $("#singleDose").attr("disabled", "true");
            $("#singleDose").attr("data-parsley-required", "false");
            $("#administration").attr("disabled", "true");
            $("#administration").attr("data-parsley-required", "false");
            $("#repeatIncaditor").removeAttr("disabled");
            $("#repeatIncaditor").attr("data-parsley-required", "true");
            $("#billingAttr").removeAttr("disabled");
            $("#billingAttr").attr("data-parsley-required", "true");
            $("#performFreq").attr("disabled", "true");
            $("#performFreq").attr("data-parsley-required", "false");
            //5 执行时间
            $("#nursePerformTime").attr("disabled", "true");
            $("#nursePerformTime").attr("data-parsley-required", "false");
        } else if (itemClass == "2") {
            $(orderTextId).flushCache();
            $(orderTextId).attr("id", "inText");
            orderTextId = "#inText";
            $("#nursePerformTime").attr("disabled", "true");
            $("#billingAttr").val(0).trigger("change");
            $("#billingAttr").attr("disabled", "true");
            $("#singleDose").removeAttr("readonly");
            $("#singleDoseUnit").removeAttr("readonly");
            $('#price').val(0);
        }
    })
</script>





<div class="content-wrap">
    <section class="panel panel-default">
        <div class="panel-body">
            <div class="col-lg-12">
                <form:form id="inputForm" data-parsley-validate="" modelAttribute="treatProjectItem" method="post"
                           class="form-horizontal">
                    <form:hidden path="id"/>
                    <form:hidden path="clinicItemId" value="${treatProjectItem.clinicItemId}"/>
                    <form:hidden path="orderClass" value="${treatProjectItem.orderClass}"/>
                    <form:hidden path="" id="itemClass" value="${doctorTempla.itemClass}"/>
                    <form:hidden path="performedBy" value="${doctorTempla.billingDept}"/>
                    <form:hidden path="newDept" value="${doctorTempla.billingDept}"/>
                    <form:hidden path="firmId"/>
                    <form:hidden path="repeatIncaditor" value="${doctorTempla.repeatIndiractor}"/>
                    <form:hidden path="parent.id" id="parentId"/>
                    <form:hidden path="applyId" value="${treatProjectItem.applyId}"/>
                    <form:hidden path="isDrug" value="${doctorTempla.itemClass}"/>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">医嘱内容：</label>

                        <div class="col-sm-8">
                            <form:input path="orderText" htmlEscape="false" class="form-control" maxlength="64"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">计价属性：</label>

                        <div class="col-sm-8">
                            <form:select path="billingAttr" itemLabel="label" itemValue="value" id="billingAttr"
                                         class="form-control" data-parsley-required="true">
                                <form:option value="" label="请选择计价属性"/>
                                <form:options items="${fns:getDictList('BILLING_ATTR')}" itemLabel="label"
                                              itemValue="value" htmlEscape="false"/>
                            </form:select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">单次使用量：</label>
                        <div class="col-sm-8">
                            <form:input path="singleDose" id="singleDose" htmlEscape="false" class="form-control"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">最小计量：</label>

                        <div class="col-sm-8">
                            <form:input path="doseUnitsMetering" id="doseUnitsMetering" htmlEscape="false" readonly="true"  class="form-control" maxlength="5"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">最小单位计量：</label>

                        <div class="col-sm-8">
                            <form:input path="singleDoseUnit" id="singleDoseUnit" htmlEscape="false" class="form-control" maxlength="5"/>                                <%--<input name="singleDoseUnit" value="${treatProjectItem.singleDoseUnit}" htmlEscape="false" readonly="true" class="form-control" maxlength="5">--%>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">最小包装单位：</label>

                        <div class="col-sm-8">
                            <form:input path="minUnits" id="minUnits" htmlEscape="false" readonly="true"  class="form-control" maxlength="5"/>
                        </div>
                    </div>


                    <%--<div class="form-group">--%>
                        <%--<label class="col-sm-4 control-label">最小单位：</label>--%>
                        <%--<div class="col-sm-8">--%>
                            <%--<form:input path="" id="singleDoseUnitName" readonly="true"  htmlEscape="false" class="form-control" maxlength="5"/>--%>
                        <%--</div>--%>
                    <%--</div>--%>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">最小规格：</label>
                        <div class="col-sm-8">
                            <form:input path="minSpec" id="minSpec" htmlEscape="false" readonly="true" class="form-control" maxlength="20"/>
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-sm-4 control-label">包装单位：</label>

                        <div class="col-sm-8">
                            <form:input path="drugUnits" id="drugUnits" htmlEscape="false" readonly="true"   class="form-control" maxlength="64"/>
                                <%--<input name="packageSpec" value="${treatProjectItem.packageSpec}" readonly="true" class="form-control" maxlength="64">--%>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">包装规格：</label>

                        <div class="col-sm-8">
                            <form:input path="packageSpec" id="packageSpec" htmlEscape="false" readonly="true"   class="form-control" maxlength="64"/>
                                <%--<input name="packageSpec" value="${treatProjectItem.packageSpec}" readonly="true" class="form-control" maxlength="64">--%>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">频次：</label>

                        <div class="col-sm-8">
                            <form:select path="performFreq" id="performFreq"  data-parsley-required="true" class="form-control" itemLabel="freqDesc" itemValue="id">
                                <form:option value="" label="请选择长期医嘱执行频次"/>
                                <form:options items="${fns:findFreqList()}" itemLabel="freqDesc" itemValue="id"
                                              htmlEscape="false"/>
                            </form:select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">途径：</label>

                        <div class="col-sm-8">
                            <form:select path="administration" data-parsley-required="true" id="administration" class="form-control">
                                <form:option value="" label="请选择用药途径"/>
                                <form:options items="${fns:getSysDictList('ADMINISTRATION_DICT')}" itemLabel="label"
                                              itemValue="id" htmlEscape="false"/>
                            </form:select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">厂商：</label>

                        <div class="col-sm-8">
                            <form:input path="firmName" htmlEscape="false" readonly="true" class="form-control" maxlength="64"/>
                            <%--<input name="firmName" value="${treatProjectItem.firmName}" readonly="true" class="form-control" maxlength="64">--%>
                        </div>
                    </div>
                    <div class="form-group">
                    <label class="col-sm-4 control-label">护士执行时间：</label>

                    <div class="col-sm-8">
                        <form:input path="nursePerformTime"   htmlEscape="false" class="form-control" maxlength="64"/>
                    </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">单价：</label>

                <div class="col-sm-8">
                    <form:input path="price" htmlEscape="false" readonly="true" class="form-control"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">医生说明：</label>

                <div class="col-sm-8">
                    <form:input path="doctInstruction" htmlEscape="false" class="form-control" maxlength="100"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <input id="btnSubmit"
                           onclick="saveSub('treatProjectItem','inputForm','${ctx}/treatProjectItem/treatProjectItem/save',
                                   '${ctx}/treatProjectItem/treatProjectItem/indexTreat?type=1&id=${treatProjectItem.applyId}','${treatProjectItem.applyId}')"
                           class="btn btn-primary" type="button" value="保 存">&nbsp;
                    <input id="btnCancel" class="btn" type="button" value="返 回">
                </div>
            </div>
            </form:form>
        </div>

</div>
</section>
</div>